package com.dqhl.community.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.base.BaseActivity;

/**
 * Created by LIENLIN on 2016/9/2.
 * 周边购物-购物详情
 */
public class ShoppingDetailItemActivity extends BaseActivity implements View.OnClickListener {

    private ImageView mIvback;
    private TextView mTvTitle;
    private ImageView mImOperation;
    private TextView mTvAccound;//支付按钮
    private TextView mTvAllMoney;//显示所有金额
    private TextView mTvNumber;//购买数量
    private ImageView mIvJian;//减号
    private ImageView mIvadd;//加号
    int num=0;//商品数量
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shopping_detail_item);
        initView();
        //接受顾客选择的商品个数，并显示总金额
        //TODO 18.00单价
        Bundle bundle = getIntent().getExtras();
        num= bundle.getInt("number");
        mTvNumber.setText(num+"");
        mTvAllMoney.setText("¥"+18.00*num);
        if (num>0){
            mIvJian.setVisibility(View.VISIBLE);
        }else {
            mIvJian.setVisibility(View.GONE);
        }

    }

    @Override
    protected void onResume() {
        super.onResume();
//        num=0;
    }

    private void initView() {
        mIvback = (ImageView) findViewById(R.id.iv_top_back);
        mTvTitle = (TextView) findViewById(R.id.tv_top_title);
        mImOperation = (ImageView) findViewById(R.id.tv_top_operation);
        mTvAccound = (TextView) findViewById(R.id.tv_account);
        mTvAllMoney = (TextView) findViewById(R.id.tv_shopping_allmoney);
        mTvNumber= (TextView) findViewById(R.id.tv_shoppingdetail_number);
        mIvJian= (ImageView) findViewById(R.id.iv_shoppingdetail_jian);
        mIvadd= (ImageView) findViewById(R.id.iv_shoppingdetail_jia);

        mIvback.setVisibility(View.VISIBLE);
        mImOperation.setVisibility(View.VISIBLE);
        mIvback.setOnClickListener(this);
        mTvAccound.setOnClickListener(this);
        mIvJian.setOnClickListener(this);
        mIvadd.setOnClickListener(this);

        mImOperation.setImageResource(R.drawable.ic_shera);
        mTvTitle.setText(R.string.txt_shoping);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_top_back:
                finish();
                break;
            case R.id.tv_account:
                //跳转支付详情页-传递：总金额，商品数
                if (num==0){
                    toast("请选择商品数量");
                }else {
                    Bundle bundle=new Bundle();
//                    bundle.putString("allmoney",mTvAllMoney.getText().toString());
//                    bundle.putInt("number",num);
//                    overlay(ShoppingAccount.class,bundle);
                    //TODO 待服务器返回真是数据
                    bundle.putString("total_money", "18");
                    bundle.putInt("number", num);
                    bundle.putString("img", "");
                    bundle.putString("name", "炒西红柿");
                    bundle.putString("goods_id", "0");
                    bundle.putString("price", "18");
                    overlay(ShoppingPaymentActivity.class, bundle);
                }

                break;
            case R.id.iv_shoppingdetail_jia:
                ++num;
                if (num==1){
//                    mTvNumber.setVisibility(View.VISIBLE);
                    mIvJian.setVisibility(View.VISIBLE);
                }
                mTvNumber.setText(num+"");
                mTvAllMoney.setText("¥"+18.00*num);
                break;
            case R.id.iv_shoppingdetail_jian:
                if (num>0){
                    mTvNumber.setText((--num)+"");
                    mTvAllMoney.setText("¥"+18.00*num);
                    if (num==0){
//                        mTvNumber.setVisibility(View.GONE);
                        mIvJian.setVisibility(View.GONE);
                    }
                }
                break;
        }
    }
}
